Documentation for Users  2.1.2
Perception Toolbox for Virtual Reality (PTVR) Manual
head_pointing_to_end_trials.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 ...\PTVR_Researchers\Python_Scripts\Demos\Pointing\events_and_callbacks_for_pointing\
4  head_pointing_to_end_trials.py
5 
6 Description :
7  Loop of trials with one scene per trial.
8  You must point at the sphere (whose position changes across trials) with
9  your head to go to the next trial.
10 
11 
12 
13 
14 
15 """
16 
17 import PTVR.SystemUtils
18 import PTVR.Visual as visual
22 import PTVR.Data.Event as event
23 import PTVR.Data.Callback as callback
24 import PTVR.Stimuli.Color as color
25 
26 from PTVR.Pointing.PointingCursor import *
28 
29 nb_of_trials = 4
30 
31 # radius of the pointing activation disk (in degrees)
32 pointing_activation_disk_radius_deg = 3
33 # increase this parameter to make pointing easier
34 
35 distance_to_sphere = 3 # in meters
36 
37 reticle_size_deg = 2 * pointing_activation_disk_radius_deg
38 # The reticle's diameter is thus equal to the diameter of the pointing
39 # activation disk.
40 
41 
42 def create_reticle(my_scene):
43  # The RETICLE
44  # This function creates the head-contingent reticle.
45  # This reticle is a head-contingent visual feedback which is not responsible for
46  # the pointing process. The latter is performed thanks to the 'pointedAt' events
47  # created further below.
48  #
49  # internally create a PNG file to create a sprite
50  reticle_2D_image = RG.ReticleImageFromDrawing()
51 
52  # transform 'reticle_2D_image' into a contingent cursor.
53  my_reticle = ImageToContingentCursor(
54  image=reticle_2D_image,
55  size_in_degrees=[reticle_size_deg, reticle_size_deg],
56  distance_if_empty_cursor_cone=distance_to_sphere
57  )
58  my_scene.place_contingent_cursor(my_reticle)
59  # END of Reticle creation.
60  # -------------------------
61 
62 
63 def main():
64 
65  my_world = visual.The3DWorld(name_of_subject="nabil")
66  my_world.translate_coordinate_system_along_global(np.array([0, 1.2, 0]))
67  text_1 = PTVR.Stimuli.Objects.Text(text="Point at sphere with your head to go to next trial",
68  fontsize_in_postscript_points=200,
69  vertical_alignment="baseline")
70  text_1.set_cartesian_coordinates(y=-2, z=2)
71 
72  for i in range(0, nb_of_trials):
73  trial_scene = PTVR.Stimuli.Scenes.VisualScene(trial=i + 1)
74  trial_text = PTVR.Stimuli.Objects.Text(text="trial : " +
75  str(trial_scene.trial),
76  fontsize_in_postscript_points=600,
77  vertical_alignment="baseline")
78  trial_text.set_cartesian_coordinates(z=2)
79 
80  my_target_sphere = PTVR.Stimuli.Objects.Sphere(
81  color=color.RGBColor(1, 0, 0, 1),
82  size_in_meters=0.2)
83  my_target_sphere.set_perimetric_coordinates(eccentricity=20,
84  halfMeridian=i * 90,
85  radialDistance=4)
86 
87  # if you do not want to have a flat cursor to get visual feedback from your head's
88  # motion and thus see if you're pointing correctly at the sphere,
89  # then comment the following line.
90  create_reticle(trial_scene)
91 
92  # Interactions allowing us to point at objects
93  # Events and Callbacks must be created BEFORE interactions !
94  # Events
95  target_is_pointed_at = \
96  event.PointedAt(
97  # What is the object that must be pointed at?
98  target_id=my_target_sphere.id,
99 
100  # Id of the pointing device:
101  # Headset is the default (shown below for didactic emphasis)
102  activation_cone_origin_id=my_world.headset.id,
103 
104  activation_cone_radius_deg=pointing_activation_disk_radius_deg)
105 
106  # Create interaction for the current scene
107  my_callback_current_scene_end = callback.EndCurrentScene()
108 
109  # Standard Interaction
110  trial_scene.AddInteraction(events=[target_is_pointed_at],
111  callbacks=[my_callback_current_scene_end])
112 
113  trial_scene.place(trial_text, my_world)
114  trial_scene.place(text_1, my_world)
115 
116  trial_scene.place(my_target_sphere, my_world)
117  my_world.add_scene(trial_scene)
118 
119  my_world.write() # Write experiment to .json file
120 
121 
122 if __name__ == "__main__":
123  main()
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182